<?php

lt_include(PLOG_CLASS_PATH.'class/plugin/pluginbase.class.php');

class Pluginmp3player extends PluginBase
{
    var $pluginEnabled;
    var $client;
    var $contentEnabled;
    var $contentWidth;
    var $contentHeight;
    var $contentFormat;
    var $contentType;
    var $contentChannel;

    function Pluginmp3player($source = "")
    {
        $this->PluginBase($source);
        $this->id = 'mp3player';
        $this->author = 'twu2 <br /> Modified by hery@serasera.org';
        $this->desc = "This plugin offers features to support google adsense.<br />Now you don't need to modify anymore your template.";
        $this->version = '0.9.3';
        $this->locales = array('en_UK', 'zh_TW');
		if ($source == "admin") {
			$this->initAdmin();
		} else {
			$this->registerNotification( EVENT_POST_LOADED );
		}
    }

    function initAdmin()
    {
        $this->registerAdminAction('mp3player', 'Pluginmp3playerConfigAction');
        $this->registerAdminAction('updatemp3player', 'Pluginmp3playerUpdateConfigAction');
        $menu =& Menu::getMenu();
        $this->addMenuEntry('/menu/controlCenter/manageSettings', 'mp3player', '?op=mp3player');
    }

    function register()
	{
        $blogSettings = $this->blogInfo->getSettings();
        $this->pluginEnabled = $blogSettings->getValue('plugin_mp3player_enabled');
    }


	function getPluginConfigurationKeys()
	{
		return( Array(
			Array( "name" => "plugin_mp3player_enabled", "type" => "boolean" ),
		));
	}


	function process( $event, $params) {

		$blogInfo = $params[ "blogInfo" ];
		$blogSettings = $blogInfo->getSettings();
		$pluginEnabled = $blogSettings->getValue( "plugin_mp3player_enabled" );


		if (!$pluginEnabled) { return true; }

		// i HARDCODED the google script first I will put the parameters later
		if( $event == EVENT_POST_LOADED && $params["from"] != "editPost" ) {
			$post = $params[ "article" ];
			$post = $this->_filter($post);
			$params[ "article" ] = $post;
		} 

	}

/*
	function _filter( $post ) {


		$config =& Config::getConfig();
		
		// modify the text...
		$player = "http://blaogy.com/plugins/mp3player/dewplayer.swf";
		$player_object =  "<span class=\"mp3\"><object type=\"application/x-shockwave-flash\" data=\"" . $player . "?son=\\1\" width=\"200\" height=\"20\" bgcolor=\"#FFFFFF\"><param name=\"movie\" value=\"plugins/mp3player/dewplayer.swf?son=\\1\" /><param name=\"bgcolor\" value=\"#FFFFFF\" /></object></span>";
		$player_regex = "/\[(([[:print:]]+\/([[:print:]]+)\.[mM][pP]3))\]/";
		$postIntroText = $post->getIntroText();
		$postExtendedText = $post->getExtendedText();
		
		$postIntroText = preg_replace($player_regex, $player_object, $postIntroText);
		$postExtendedText = preg_replace($player_regex, $player_object, $postExtendedText);

		$post->setText( $postIntroText.POST_EXTENDED_TEXT_MODIFIER.$postExtendedText );
		
		return $post;
	}

*/

	function _filter($post)
	{
		$postIntroText = $post->getIntroText();
		$postExtendedText = $post->getExtendedText();
		define("DEWMP3_PLAYER", "http://blaogy.org/wp-content/mu-plugins/dewplayer.swf");
		define("DEWMP3_WIDTH", 200);
		define("DEWMP3_HEIGHT", 20);
		define("DEWMP3_BACKGROUND", "#DFDFDF");
		define("DEWMP3_REGEXP", "/\[([[:print:]]+\/([[:print:]]+)\.[mM][pP]3)\]/");
		define("DEWMP3_TARGET", "<span class=\"mp3\"><object type=\"application/x-shockwave-flash\" data=\"".DEWMP3_PLAYER."?son=###URL###\" width=\"".DEWMP3_WIDTH."\" height=\"".DEWMP3_HEIGHT."\" bgcolor=\"".DEWMP3_BACKGROUND."\"><param name=\"movie\" value=\"".DEWMP3_PLAYER."?son=###URL###\" /><param name=\"bgcolor\" value=\"".DEWMP3_BACKGROUND."\" /></object></span>");

		$postIntroText = preg_replace(DEWMP3_REGEXP, DEWMP3_TARGET, $postIntroText);
		$postExtendedText = preg_replace(DEWMP3_REGEXP, DEWMP3_TARGET, $postExtendedText);

		$post->setText( $postIntroText.POST_EXTENDED_TEXT_MODIFIER.$postExtendedText );
		return $post;
	}


}

?>
